//
//  NetworkConnectivityManager.swift
//  DMRCommonBaseLib
//
//  Created by Riven on 2025/11/4.
//

import Foundation

// Module 'xxx' was not compiled with library evolution support; using it means binary compatibility for 'xxxxx' can't be guaranteed
// https://forums.swift.org/t/library-evolution-support-warning/59344
//@_implementationOnly import Connectivity
//internal import Connectivity
//
//open class NetworkConnectivityManager: NSObject {
//    
//    @objc public enum NetworkConnectivityStatus: Int, CustomStringConvertible {
//        case connected, // where a connection is present but the interface cannot be determined.
//             connectedViaCellular,
//             connectedViaCellularWithoutInternet,
//             connectedViaEthernet,
//             connectedViaEthernetWithoutInternet,
//             connectedViaWiFi,
//             connectedViaWiFiWithoutInternet,
//             determining,
//             notConnected
//
//        public var description: String {
//            switch self {
//            case .connected:
//                return "Internet access"
//            case .connectedViaCellular:
//                return "Cellular with Internet access"
//            case .connectedViaCellularWithoutInternet:
//                return "Cellular without Internet access"
//            case .connectedViaEthernet:
//                return "Ethernet with Internet access"
//            case .connectedViaEthernetWithoutInternet:
//                return "Ethernet without Internet access"
//            case .connectedViaWiFi:
//                return "Wi-Fi with Internet access"
//            case .connectedViaWiFiWithoutInternet:
//                return "Wi-Fi without Internet access"
//            case .determining:
//                return "Connectivity checks pending"
//            case .notConnected:
//                return "No Connection"
//            }
//        }
//    }
//    
//    public static let shared = NetworkConnectivityManager()
//    
//    public var status: NetworkConnectivityStatus {
//        let status = NetworkConnectivityStatus.init(rawValue: connectivity.status.rawValue) ?? .determining
//        return status
//    }
//    
//    let connectivity = Connectivity()
//    var connectivityChangedCompletion: ((NetworkConnectivityStatus) -> Void)?
//    
//    private override init() {
//        super.init()
//        
//        let connectivityChanged: (Connectivity) -> Void = { [weak self] connectivity in
//            guard let self = self else {
//                return
//            }
//            self.connectivityChangedCompletion?(self.status)
//        }
//
//        connectivity.whenConnected = connectivityChanged
//        connectivity.whenDisconnected = connectivityChanged
//    }
//    
//    
//    public func startNotifier(_ changedAction: ((NetworkConnectivityStatus) -> Void)?) {
//        connectivityChangedCompletion = changedAction
//        connectivity.startNotifier()
//    }
//    
//    public func stopNotifier() {
//        connectivity.stopNotifier()
//        connectivityChangedCompletion = nil
//    }
//    
//    public func checkConnectivityOnece(_ completion: ((NetworkConnectivityStatus) -> Void)?) {
//        connectivity.checkConnectivity { [weak self] connectivity in
//            guard let self = self else {
//                return
//            }
//            
//            completion?(self.status)
//        }
//    }
//    
//}
